﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>车型信息</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/commonSelecter.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
var _pagination = null;
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
});

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#cartypeTable").empty();
	var name = $("#carsysName").val();
	var carSysId = $("#selectCarsys").val();
	if(IsEmpty(carSysId)){
		carSysId = '';
	}
	_pagination = new Pagination({
		url : '../carType/find/all',
		data : {
			name : name,
			carSysId : carSysId
		},
		success : printDataToPage,
		pageSize : 10
	});
}

/**
 * 删除一行
 */
function toDelete(id,carSysId,row) {
	if (IsEmpty(id)) {
		artError('未获取到主要信息！');
		return false;
	}
	
	
	artConfirm("确认删除吗？", function() {
		qmsk.post("../carType/del",{'id' : id}, function(rst) {
			artSuccess("删除成功！");
			toSearch();
		});
	});
}


function printDataToPage(message){
	dataTable({
		tbodyId : 'cartypeTable',
		heads : ["code", "name", "carSysName","BrandName","Emissions","SeatCount","FirstMile","RoutineMile","importName","staName",["id","carSysId"]],
		rst : message,
		handler : [{
			col : 10,
			f : detail
		}],
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel() {
	$("#window_change,#yinying1").hide();
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel1() {
	$("#window_change1,#yinying1").hide();
}

function selectCarsysser(){
	$("#selectCarsys").blur();
	initSelecter({
		url : '../carSystem/find/all',
		heads : ["code", "name"],
		titles : ["编码", "车系名称"],
		zindex : 500,
		callBack : callBack
	});
}

function callBack(response, row) {
	var id = response.getValue('id', row);
	var name = response.getValue('name', row);
	$("#selectCarsys").append("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
}

function selectCarsys(){
	$("#editCarSysType").blur();
	$("#addCarSytType").blur();
	addMargin($("#window3"));
	new Pagination({
		url : '../brand/find/all',
		success : brandF,
		pagerHandler:'brandPager',
		pageSize : 4
	});
	$("#window3,#yinying").show();
}

function brandF(message){
	dataTable({
		tbodyId : 'tbrandType',
		heads : ["code", "name", "id"],
		trGender:trGender,
		rst : message
	});
	$("tbody[id=tbrandType] tr td:last-child").hide();
	addMargin($("#window3"));
}

/*
*重置tr标签
*/
function trGender(row){
	if(IsNotEmpty(row)){
		return "<tr id='brandId"+row+"' onclick='findCarSys("+row+")'></tr>";
	}
}

function findCarSys(row){
	$("tbody[id=tbrandType] tr td").css("background","#fff");
	$("#brandId"+row).find("td").css("background","#007AC2");
	var brandId = $("#brandId"+row).find("td:eq(2)").text();
	if(IsNotEmpty(brandId)){
		$("#brandId").val(brandId);
		new Pagination({
			url : '../carSystem/find/brandId/'+brandId,
			success : carSysF,
			pagerHandler:'CarSysPager',
			pageSize : 4
		});
	}
}

function carSysF(message){
	dataTable({
		tbodyId : 'tCarSys',
		heads : ["code", "name", "id"],
		handler : [{
			col : 2,
			f : carSysbtn
		}],
		trGender:trGenders,
		rst : message
	});
}

function trGenders(row){
	if(IsNotEmpty(row)){
		return "<tr id='Id"+row+"'></tr>";
	}
}

function carSysbtn(heads, row){
	return "<input class='common_btn' type='button' value='选择' onclick='toSelected("+heads+","+row+")'>";
}

function toSelected(id,row){
	var tpname =$("#Id"+row).find("td:eq(1)").text();
	$("#editCarSysType").append("<option value='" + id + "' selected=\"selected\" >" + tpname + "</option>");
	$("#addCarSytType").append("<option value='" + id + "' selected=\"selected\" >" + tpname + "</option>");
	$("#window3,#yinying").hide();
}

function toAdd(){
	$("#addName").val("");
	$("#addCode").val("");
	$("#addCarSytType").empty();
	$("#addEmissions").val("");
	$("#addSeatCount").val("");
	$("#addFirstMile").val("");
	$("#addRoutineMile").val("");
	$("#addStatus option:first").attr('selected','selected');
	$("#addIsImported option:first").attr('selected','selected');
	$("#window_change,#yinying1").show();
	addMargin($("#window_change"));
}

function toEdit(id,carSysId){
	$("#window_change1,#yinying1").show();	
	addMargin($("#window_change1"));
	var rst = _findInfo("../carType/find/id",{"id":id});
	if (IsNotEmpty(rst)){
  		$("#editCarSysType").append("<option value='" + getHtmlString(getHeadIndexValue(0,rst,'carSysId')) + "' selected=\"selected\" >" + getHtmlString(getHeadIndexValue(0,rst,'carSysName')) + "</option>");
		$("#editName").val(getHtmlString(getHeadIndexValue(0,rst,'name')));
		$("#editCode").val(getHtmlString(getHeadIndexValue(0,rst,'code')));
		$("#editEmissions").val(getHtmlInt(getHeadIndexValue(0,rst,'Emissions')));
		$("#editSeatCount").val(getHtmlInt(getHeadIndexValue(0,rst,'SeatCount')));
		$("#editFirstMile").val(getHtmlInt(getHeadIndexValue(0,rst,'FirstMile')));
		$("#editRoutineMile").val(getHtmlInt(getHeadIndexValue(0,rst,'RoutineMile')));
		var status = getHtmlInt(getHeadIndexValue(0,rst,'Status'));
		if(status == 0){
			$("#editStatus option:first").attr('selected','selected');
		}else{
			$("#editStatus option:last").attr('selected','selected');
		}
		
		var isImported = getHtmlInt(getHeadIndexValue(0,rst,'IsImported'));
		if(isImported == 0){
			$("#editIsImported option:first").attr('selected','selected');
		}else{
			$("#editIsImported option:last").attr('selected','selected');
		}
/* 		$("#editStatus").append("<option value='" + getHtmlString(getHeadIndexValue(0,rst,'Status')) + "' selected=\"selected\" >" + getHtmlString(getHeadIndexValue(0,rst,'staName')) + "</option>");
		$("#editIsImported").append("<option value='" + getHtmlString(getHeadIndexValue(0,rst,'IsImported'))+ "' selected=\"selected\" >" + getHtmlString(getHeadIndexValue(0,rst,'importName')) + "</option>");
 */		
 		$("#cartypeId").val(getHtmlString(getHeadIndexValue(0,rst,'id')));
	}
}

function edit(){
	var carSysId = $("#editCarSysType").val();
	var name = $("#editName").val();
	var code = $("#editCode").val();
	var emissions = $("#editEmissions").val();
	var seatCount = $("#editSeatCount").val();
	var firstMile = $("#editFirstMile").val();
	var routineMile= $("#editRoutineMile").val();
	var status = $("#editStatus").val();
	var isImported = $("#editIsImported").val();
	var id = $("#cartypeId").val();
	if(IsEmpty(carSysId)){
		art.dialog({fixed:true, lock: true,content:"车系不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(emissions) && (!(_checkMoney(emissions)))){
		art.dialog({fixed:true, lock: true,content:"您输入的排量非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(seatCount) && (!(_checkMoney(seatCount)))){
		art.dialog({fixed:true, lock: true,content:"您输入的座位号非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(firstMile) && (!(_checkMoney(firstMile)))){
		art.dialog({fixed:true, lock: true,content:"您输入的首保里程非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(routineMile) && (!(_checkMoney(routineMile)))){
		art.dialog({fixed:true, lock: true,content:"您输入的常规保养非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"名称不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"id不能为空",icon:'error',ok:true});	
		return false;
	}
	var heads = new Array("name","code","Emissions","SeatCount","FirstMile","RoutineMile","IsImported","Status","carSysId","id");
	var datas = new Array(name,code,emissions,seatCount,firstMile,routineMile,isImported,status,carSysId,id);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "edit" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../carType/edit", {
		data : jsonParserStr
	}, function() {
		artSuccess("修改成功！");
		hideAddPanel1();
		if (_pagination) {
			_pagination.reload();
		}
	});
}

function add() {
	var carSysId = $("#addCarSytType").val();
	var name = $("#addName").val();
	var code = $("#addCode").val();
	var emissions = $("#addEmissions").val();
	var seatCount = $("#addSeatCount").val();
	var firstMile = $("#addFirstMile").val();
	var routineMile= $("#addRoutineMile").val();
	var status = $("#addStatus").val();
	var isImported = $("#addIsImported").val();
	
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"名称不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(carSysId)){
		art.dialog({fixed:true, lock: true,content:"车系不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(emissions) && (!(_checkMoney(emissions)))){
		art.dialog({fixed:true, lock: true,content:"您输入的排量非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(seatCount) && (!(_checkMoney(seatCount)))){
		art.dialog({fixed:true, lock: true,content:"您输入的座位号非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(firstMile) && (!(_checkMoney(firstMile)))){
		art.dialog({fixed:true, lock: true,content:"您输入的首保里程非正常",icon:'error',ok:true});	
		return false;
	}
	
	if(IsNotEmpty(routineMile) && (!(_checkMoney(routineMile)))){
		art.dialog({fixed:true, lock: true,content:"您输入的常规保养非正常",icon:'error',ok:true});	
		return false;
	}
	
	var heads = new Array("name","code","Emissions","SeatCount","FirstMile","RoutineMile","IsImported","Status", "carSysId");
	var datas = new Array(name,code,getHtmlInt(emissions),getHtmlInt(seatCount),getHtmlInt(firstMile),getHtmlInt(routineMile),isImported,status,carSysId);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../carType/insert", {
		data : jsonParserStr
	}, function() {
		artSuccess("添加成功！");
		hideAddPanel();
		toSearch();
	});
}

function detail(heads, row){
	return	"<input class='del common_btn' type='button' value='删除' onclick='toDelete("+heads[0]+","+heads[1]+","+row+")'>"+"<input class='edit common_btn' type='button' value='修改' onclick='toEdit("+heads[0]+","+heads[1]+")'>";
}


</script>
</head>

<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>
			<div class="hideDiv hideOver" id="window3" style="width: 600px;">
			 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
				<table id="tabBrandType" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
			    	<caption>品牌列表</caption>
			    	<thead>
				    	<tr>
				        	<th>品牌编码</th>
				        	<th>品牌名称</th>
				        </tr>
			        </thead>
			        <tbody id="tbrandType">
			        </tbody>
			    </table>
 				<div id="brandPager" class="pager"></div>
 			
 				<table id="tabCarSys" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
			    	<caption>车系列表</caption>
			    	<thead>
				    	<tr>
				        	<th>车系编码</th>
				        	<th>车系名称</th>
				        	<th>操作</th>
				        </tr>
			        </thead>
			        <tbody id="tCarSys">
			        </tbody>
			    </table>
 				<div id="CarSysPager" class="pager"></div>
 			</div>
 			
		
		<!-- 添加记录 弹出层 -->
		<div id="window_change" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label ><span style="width:136px;">车型名称：</span>
					<input type="text" id="addName" class="absoluteTxt">
				</label>
				<label><span>车型编码：</span>
					<input type="text" id="addCode" class="absoluteTxt">
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">排放量：</span>
					<input type="text" id="addEmissions" class="absoluteTxt">
				</label>
				<label ><span>车系名称：</span>
					<select id="addCarSytType" onclick="selectCarsys()"></select>
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">首保里程(公里)：</span>
					<input type="text" id="addFirstMile" class="absoluteTxt">
				</label>
				<label ><span>座位数：</span>
					<input type="text" id="addSeatCount" class="absoluteTxt">
				</label>
			</p>
			<p>
				<label ><span>常规保养里程(公里)：</span>
					<input type="text" id="addRoutineMile" class="absoluteTxt">
				</label>
				<label ><span>是否进口：</span>
					<select id="addIsImported"><option value="0">国产</option><option value="1">进口</option></select>
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">状态：</span>
					<select id="addStatus" ><option value="0">正常</option><option value="1">停用</option></select>
				</label>
			</p>
			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="saveButton" onclick="add()">
			</div>
		</div>
		
		<div id="window_change1" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label><span style="width:136px;">车型名称：</span>
					<input type="text" id="editName" class="absoluteTxt">
					<input type="hidden" id="cartypeId">
				</label>
				<label><span>车型编码：</span>
					<input type="text" id="editCode" class="absoluteTxt">
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">排放量(L)：</span>
					<input type="text" id="editEmissions" class="absoluteTxt">
				</label>
				<label><span>车系名称：</span>
					<select id="editCarSysType" onclick="selectCarsys()"></select>
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">首保里程(公里)：</span>
					<input type="text" id="editFirstMile" class="absoluteTxt">
				</label>
				<label ><span>座位数：</span>
					<input type="text" id="editSeatCount" class="absoluteTxt">
				</label>
			</p>
			<p>
				<label ><span>常规保养里程(公里)：</span>
					<input type="text" id="editRoutineMile" class="absoluteTxt">
				</label>
				<label ><span>是否进口：</span>
					<select id="editIsImported"><option value="0">国产</option><option value="1">进口</option></select>
				</label>
			</p>
			<p>
				<label ><span style="width:136px;">状态：</span>
					<select id="editStatus" ><option value="0">正常</option><option value="1">停用</option></select>
				</label>
			</p>
			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="editButton" onclick="edit()">
			</div>
		</div>
		<input type="hidden" id="brandId">
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">车型</div>
    <div class="member_search">
      <p><span>
         车型名称：<input type="text" id="carsysName" class="absoluteTxt"></span>
        <span>车系名称：<select id="selectCarsys" onclick="selectCarsysser()"></select></span>
        <span><input type="button" value="查询" class="btn" onclick="toSearch()"></span>
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>车型列表 <span id="sup">共0条</span></strong><input
						type="button" class="common_btn" value="新增" id="addColumn" onclick="toAdd()">
      </caption>
      <thead>
        <tr>
          <th>编码</th>
          <th>车型名称</th>
          <th>所属车系</th>
          <th>所属品牌</th>
          <th>排放量</th>
          <th>座位数</th>
          <th>首保里程(公里)</th>
          <th>常规里程(公里)</th>
          <th>是否进口</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="cartypeTable">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
